package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.mongodb.BasicDBObject;
import com.ymt.core.tool.Logger;
import com.ymt.database.MongoDBDriver;

/************************************************************************************
 * @File name :LiveProductInfoWapper.java
 * @Author : xujiewei
 * @Date : 2016年6月28日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
public class LiveProductInfoWapper {
	MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_YmtProductDBdriver("LiveProductInfo");

	public LiveProductInfoWapper()  {
	}
		

    public Map<String, Object> getliveproductByProductId(String productID) throws Exception {
    	 Map<String, Object> scmb = new HashMap<String, Object>();
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productID + "\"}",1);
	             try {
	            if (list.size() > 0) {
	                scmb = list.get(0);
	                return scmb;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data productId:" + productID);
	            e.printStackTrace();
	        }
	        return null;
	  }
    
    public Map<String, Object> getliveproductByLiveId(int liveId) throws Exception {
   	 Map<String, Object> scmb = new HashMap<String, Object>();
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"LiveId\":" + liveId + "}",1);
	             try {
	            if (list.size() > 0) {
	                scmb = list.get(0);
	                return scmb;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data LiveId:" + liveId);
	            e.printStackTrace();
	        }
	        return null;
	  }
    
    
    
	    
	
	public boolean update(Map<String, Object> searchMap,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(searchMap, updateMap).isUpdateOfExisting();
	}
	
	
	public int getCountByActivityId(int activityId) throws Exception{
		return mdd.selectPartLimitToMap("{\"ActivityId\":" + activityId + "}",50).size();
	}
		    
	   
	public static void main(String[] args) throws Exception {
		
		LiveProductInfoWapper aa  = new LiveProductInfoWapper();
		Map<String, Object> bb = aa.getliveproductByLiveId(151992);	
		Logger.debug(bb);
		
//		Map<String, Object> bb = aa.getliveproductByProductId("8b8974b8-6dae-4ce7-8ef2-294d8d252c97");	
//		BasicDBObject activityCategory = (BasicDBObject) bb.get("ActivityCategory");
//		int categoryId = activityCategory.getInt("CategoryId");
//		Logger.debug(bb);
//		Logger.debug(categoryId);
		
//		LiveBasicInfoBean liveBasicInfoBean= new LiveProductInfoWapper().getliveproductByProductId("da5d56c4-9b4d-4ee5-a3b7-1666198ddea1");	
//		String categoryNameStr =  new JSONArray(FormatUtil.beanToGSONString(liveBasicInfoBean.getCategoryList())).getJSONObject(0).getString("CategoryName");
//		System.out.println(categoryNameStr);
		
		
		
		//System.out.print(new JSONArray(liveBasicInfoBean.getCategoryList().toString()).getJSONObject(0).getString("CategoryName"));
		
	}    
	
	    
}
